package pbl;

import java.net.*;

/**
 * 
 * @author @author AMPM
 *
 */

public class UdpReceiver{
	public static void main(String args[ ]) throws Exception{ 
		// the datagram socket object is created
		int receiversPort = 6789;		                                                 
		DatagramSocket datagramSocket = new DatagramSocket( receiversPort );
		
		// data from the udp sender is buffered and a datagram packet is created
		byte[ ] buffer = new byte[1000]; // max 65.536 bytes
		DatagramPacket datagramPacket = new DatagramPacket(buffer, buffer.length);
		datagramSocket.receive( datagramPacket );
		
		// the data is turned into a string and printed
		String message = new String( datagramPacket.getData() );
		message = message.trim(); //removes white spaces
		System.out.println( message );
  	}
}